<template>
  <div>
    <a-modal :title="title" :visible="visible" @before-open="open" @cancel="handleCancel" :align-center="false" title-align="start" width="600px" :mask-closable="false">
      <div v-if="title == '撤回待审核'">
        <div class="title">请再次确认是否将该订单撤回到到待审核状态</div>
        <div class="desc">此处撤回的是当前包裹，如果订单上有多个包裹，其他的不受影响。</div>
      </div>
      <div v-else>
        <div class="title">请再次确认是否将该出库单撤回到待处理状态？</div>
        <div class="desc">撤回后会将已锁定的库存解锁掉</div>
      </div>
      <template #footer>
        <a-button class="gray-outline" @click="handleCancel">取消</a-button>
        <a-button type="primary" :loading="loading" class="ml10" @click="handleOk">确认</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRefs, computed } from 'vue'
  import { Message } from '@arco-design/web-vue'
  import { rollbackTocheck, rollbackTohand } from '@/api/order'
  export default defineComponent({
    props: ['title', 'ids'],
    setup(props: any, { emit }) {
      let visible = ref(false)
      const data = reactive({
        loading: false,
      })

      const open = () => {}
      const handleOk = async () => {
        let res: any = {}
        data.loading = true
        try {
          if (props.title == '撤回待审核') {
            res = await rollbackTocheck(props.ids)
          } else {
            res = await rollbackTohand(props.ids)
          }
          data.loading = false
          if (res) {
            props.title == '撤回待审核' ? Message.success('撤回待审核成功') : Message.success('撤回待处理成功')
            visible.value = false
            emit('save')
          }
        } catch (error) {
          data.loading = false
        }
      }
      const handleCancel = () => {
        visible.value = false
      }
      return {
        ...(toRefs(data) as any),
        visible,
        open,
        handleOk,
        handleCancel,
      }
    },
  })
</script>

<style lang="less" scoped>
  .desc {
    font-size: 10px;
    color: #aaaaaa;
  }
</style>
